package com.ocom.webapi.controller;

import cn.hutool.core.convert.Convert;
import com.ocom.common.constant.WebApiServiceUrl;
import com.ocom.common.entity.payconfig.EntityReceiptAddressPrice;
import com.ocom.common.request.web.AdReceiptPageDeletePricerRequest;
import com.ocom.common.request.web.AdReceiptPagePriceListRequest;
import com.ocom.common.request.web.AdReceiptPageSavePriceRequest;
import com.ocom.common.resp.Result;
import com.ocom.security.authentication.YoCiUser;
import com.ocom.security.utils.SecurityUtils;
import com.ocom.webapi.feign.PayConfigClientService;
import lombok.extern.log4j.Log4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@Log4j
@RestController
@PreAuthorize("@pms.hasRole('ROLE_WEB')" )
public class ReceiptAddressPriceController {
    @Autowired
    public PayConfigClientService payConfigClientService;

    @PostMapping(WebApiServiceUrl.URL_AdReceiptPage_priceList)
    public Result AdReceiptPagePriceList(@RequestBody AdReceiptPagePriceListRequest request){
        YoCiUser yoCiUser = SecurityUtils.getYoCiUser();
        EntityReceiptAddressPrice entityReceiptAddressPrice = Convert.convert(EntityReceiptAddressPrice.class,request);
        entityReceiptAddressPrice.setComId(yoCiUser.getComId());
        return this.payConfigClientService.getReceiptAddressPriceList(entityReceiptAddressPrice);
    }

    @PostMapping(WebApiServiceUrl.URL_AdReceiptPage_savePrice)
    public Result AdReceiptPageSavePrice(@RequestBody AdReceiptPageSavePriceRequest request){
        YoCiUser yoCiUser = SecurityUtils.getYoCiUser();
        EntityReceiptAddressPrice entityReceiptAddressPrice = Convert.convert(EntityReceiptAddressPrice.class,request);
        entityReceiptAddressPrice.setComId(yoCiUser.getComId());
        entityReceiptAddressPrice.setCreateUserid(yoCiUser.getId());
        return this.payConfigClientService.setReceiptAddressPrice(entityReceiptAddressPrice);
    }

    @PostMapping(WebApiServiceUrl.URL_AdReceiptPage_deletePrice)
    public Result AdReceiptPageDeletePrice(@RequestBody AdReceiptPageDeletePricerRequest request){
        YoCiUser yoCiUser = SecurityUtils.getYoCiUser();
        EntityReceiptAddressPrice entityReceiptAddressPrice = Convert.convert(EntityReceiptAddressPrice.class,request);
        entityReceiptAddressPrice.setComId(yoCiUser.getComId());
        return this.payConfigClientService.removeReceiptAddressPrice(entityReceiptAddressPrice);
    }
}
